<?php
$form = $this->beginWidget('CActiveForm', array(
    "id" => "addTypeForm",
    'enableAjaxValidation' => FALSE,
    'htmlOptions' => array('enctype' => 'multipart/form-data'),
        ));
$url = $control->getAjaxLinkUrl('addMemberCardType', NULL, array(
    'cooker' => 'BAMemberCard@addCardType',
    'preCardType' => $preCardType,
    'memberCardTypeId' => $memberCardTypeId));
$updateId = $control->getAjaxContainerId();
?>

<script type="text/javascript">
// this script for collecting the form data and pass to the controller action and doing the on success validations
    function send<?php echo $memberCardTypeId; ?>() {

        var formData = new FormData($("#addTypeForm")[0]);
        $.ajax({
            url: '<?php echo $url; ?>',
            type: 'POST',
            data: formData,
            //datatype: 'json',
            // async: false,
            beforeSend: function() {
                $("#ajax-loaderdiv").show();
            },
            success: function(html) {
                // on success do some validation or refresh the content div to display the uploaded images 
                jQuery("#<?php echo $updateId; ?>").html(html);
            },
            complete: function() {
                $("#ajax-loaderdiv").hide();
            },
            error: function(data) {
                alert("There may a error on uploading. Try again later");
            },
            cache: false,
            contentType: false,
            processData: false
        });

        return false;
    }
</script>
<legend>
    <h4>
        <?php
        echo $control->getAjaxLink(array('name' => '功能列表', 'id' => 'showEventList'), array(
            'cooker' => 'BAEventCooker@showEventList'
        ));
        ?>\
        <?php
        echo $control->getAjaxLink(array('name' => '会员卡类型', 'id' => 'showCardList'), array(
            'cooker' => 'BAMemberCard@showCardTypeList'
        ));
        ?>\
        <?php
        echo $control->getAjaxLink(array('name' => '添加会员卡', 'id' => 'showAddCardType'), array(
            'cooker' => 'BAMemberCard@showAddCardType'
        ));
        ?>
        \设置类型
    </h4>
</legend>
<div class="tabbable tabs-right" style="margin-top: 15px;"> <!-- Only required for left/right tabs -->
    <ul class="nav nav-tabs" style="margin-bottom: 15px">
        <li class="active"><a href="#tab1" data-toggle="tab"><?php echo '基本设置'; ?></a></li>    
        <li class=""><a href="#tab2" data-toggle="tab"><?php echo '申请设置'; ?></a></li>    
        <li class=""><a href="#tab3" data-toggle="tab"><?php echo '其他属性'; ?></a></li>
    </ul>
    <div class="tab-content">
        <div class="tab-pane active" id="tab1" style="min-height: 120px">                
            <?php
            $control->renderView('memberCardType_add_info', array(
                'model' => $model,
                'typeNameField' => $typeNameField,
                'typeAliasField' => $typeAliasField,
                'templateField' => $templateField,
                'memberPointTypeField' => $memberPointTypeField,
                'moneyField' => $moneyField,
                'memberCardTypeId' => $memberCardTypeId,
                'preCardType' => $preCardType
            ));
            ?>  
        </div>  
        <div class="tab-pane" id="tab2" style="min-height: 120px">                
            <?php
            if (isset($memberCardType) && $memberCardType != NULL) {
                $control1 = new BUIEventControl('permitControl');
                $mCardCooker = new BAMemberCardCooker();
                $mCardCooker->showApplyPermitList($control1);
            } else {
                echo '<div class="well"><h5 class="text-warning">需要先保存类型，然后再添加申请规则</h5></div>';
            }
            ?>  
        </div>
        <div class="tab-pane" id="tab3" style="min-height: 120px">                
            <?php
            if (isset($memberCardType) && $memberCardType != NULL) {
                $control1 = new BUIAttribute('showMemberCardTypeAttribute');

                $control1->prepareAttributeView('memberCardTypeAttribute', $memberCardType, 'add_memberCardType');
                $control1->render();
            } else {
                echo '<div class="well"><h5 class="text-warning">需要先保存类型，然后再添加属性</h5></div>';
            }
            ?>  
        </div>
    </div>
</div>
<?php
$this->endWidget();
//echo CHtml::endForm();
?>
<button class="btn" onclick="javascript:send<?php echo $memberCardTypeId; ?>()"><?php echo '保存设置' ?></button>
<?php
echo $control->getAjaxLink('显示列表', array(
    'cooker' => 'BAMemberCard@showCardTypeList',
    'htmlOptions' => array('class' => 'btn')
));
?>
